package com.ebring.shareEducation.controller;

import com.ebring.shareEducation.bean.User;
import com.ebring.shareEducation.bean.UserInfo;
import com.ebring.shareEducation.bean.response.UserRsp;
import com.ebring.shareEducation.service.EmailService;
import com.ebring.shareEducation.service.UserInfoService;
import com.ebring.shareEducation.service.UserService;
import com.ebring.shareEducation.utils.Md5Utils;
import com.ebring.shareEducation.utils.RspMsg;
import com.ebring.shareEducation.utils.SendSMS;
import com.github.pagehelper.PageHelper;
import com.itextpdf.text.pdf.qrcode.BitMatrix;
import com.itextpdf.text.pdf.qrcode.QRCodeWriter;
import com.itextpdf.text.pdf.qrcode.WriterException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin(origins = "http://wangliang.vipgz1.idcfengye.com", maxAge = 3600)
@Api(value = "用户注册登录" ,tags = {"用户注册登录接口"})
public class RegisterLoginController {

    @Autowired
    private UserService userService;

    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private StringRedisTemplate template;

    @Autowired
    private EmailService emailService;

    /**
     * 用户登录
     *
     * @param userId   用户ID
     * @param password 密码
     * @return map
     */
    @PostMapping("/user/login")
    @ApiOperation(value="管理端登录", notes="管理端登录")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name = "userId", value = "用户编号", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType="query",name = "password", value = "密码", required = true, dataType = "Integer"),
    })
    public RspMsg<User> login(String userId, String password) {

        return userService.login(userId, password);
    }




















    /**
     * 查找所有用户
     *
     * @param
     * @return
     */
    @GetMapping("/userinfo/selectusers")

    @ApiOperation(value="获取客户列表", notes="获取客户列表")
    public RspMsg<UserInfo> selectUserfind() {
        return userInfoService.selectUsersfind();
    }


    /**
     * 根据用户id查询用户角色的基本信息
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/userinfo/findUserByuserId")
    @ApiOperation(value="根据用户id查询用户角色的基本信息", notes="根据用户id查询用户角色的基本信息")
    @ApiImplicitParams({

            @ApiImplicitParam(paramType="query",name = "userId", value = "用户id", required = true, dataType = "String"),
    })
    public RspMsg<UserInfo> findUserinfoByuserId(String userId) {
        return userInfoService.selectUserByUserId(userId);


    }



    /**
     * 更新用户
     *
     * @param
     * @return 更新成功的结果
     */
    @PostMapping("/userinfo/updatelock")
    @ApiOperation(value="锁定用户", notes="锁定用户")
    @ApiImplicitParams({

            @ApiImplicitParam(paramType="query",name = "userid", value = "用户id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query",name = "locking", value = "锁定状态：解锁“S”，锁定“F”", required = true, dataType = "String"),
    })    public RspMsg<UserInfo> updateLock(String userid,String locking) {

        return userInfoService.updateLocking(userid,locking);
    }

    /**
     * 实名认证审核通过
     *
     * @param
     */
    @PostMapping("/userinfo/updateCert")
    @ApiOperation(value="实名认证审核通过", notes="实名认证审核通过")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name = "userid", value = "用户id", required = true, dataType = "String"),
    })    public RspMsg<UserInfo> updateCert(String userid) {

        return userInfoService.updateCert(userid);
    }


}


